//leetcode 36 有效的数独
public class Test1 {
    //row用来记录第n行的某个数字是否存在
    //col用来记录第n列的某个数字是否存在
    //grid用来记录第(i/3, j/3)个小宫格的某个数字是否存在
    boolean[][] row, col;
    boolean[][][] grid;
    public boolean isValidSudoku(char[][] board) {
        row = new boolean[9][10];
        col = new boolean[9][10];
        grid = new boolean[3][3][10];
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                if (board[i][j] != '.') {
                    int num = board[i][j] - '0';
                    if (!row[i][num] && !col[j][num] && !grid[i/3][j/3][num]) {
                        row[i][num] = col[j][num] = grid[i/3][j/3][num] = true;
                    }else {
                        return false;
                    }
                }
            }
        }
        return true;
    }
}
